let teststr :string="4193 with words";
console.log(myAtoi(teststr));

function myAtoi(s: string): number {
    let result:number=0;
    let i=0;
    while(s[i]===" "){
        i++;
    }
    let flag:boolean=true;
    let num=1;
    for (; i < s.length; i++) {
        if(s[i]===" ")
            break
        if((s[i]==='-'||s[i]==='+')&&flag)
            {
                flag=false
                num=s[i]==='-'? -1:1
                while(s[i]==='0')
                    i++;
                continue
            }
        if( !isNaN( Number(s[i]) ) )
            {
                flag=false
                result=result*10+parseInt(s[i],10)
                continue
                
            }
        break;
    }
    result=result*num;
    if(result>=Math.pow(2,31))
        result=Math.pow(2,31)-1;
    if(result<(-1*Math.pow(2,31)))
        result=-1*Math.pow(2,31)
    return result;
};